package com.xingkeduo.business.operation.service;

import com.xingkeduo.dao.database.DatabaseAccessObject;
import com.xingkeduo.pojo.query.ShopUpdateLogQuery;
import com.xingkeduo.pojo.table.ShopUpdateLogTable;
import com.xingkeduo.util.pojo.domain.Page;
import com.xingkeduo.util.tool.CommonUtil;
import com.xingkeduo.util.tool.IdentityUtil;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * 文件概述
 *
 * @author chenxiangda <chenxiangda@xingkeduo.com>
 * @version 2019年5月22日 16:03:54
 * @package BeautyOS
 * @copyright Copyright (c) XKD 2019
 */
@Component
public class ShopUpdateLogService {
    private static final String NAMESPACE = ShopUpdateLogTable.class.getSimpleName();

    @Resource(name = "mysqlOperationDao")
    private DatabaseAccessObject<ShopUpdateLogTable, ShopUpdateLogQuery> dao;

    //查询一条
    public ShopUpdateLogTable selectById(long id) throws Throwable {
        ShopUpdateLogTable shopUpdateLogTable = dao.select(NAMESPACE, id);
        if (!CommonUtil.isEmpty(shopUpdateLogTable))
            return shopUpdateLogTable;
        return null;
    }

    //查询一条
    public ShopUpdateLogTable selectByCode(long code) throws Throwable {
        ShopUpdateLogTable shopUpdateLogTable = dao.select(NAMESPACE, code);
        if (!CommonUtil.isEmpty(shopUpdateLogTable))
            return shopUpdateLogTable;
        return null;
    }

    //查询多条
    public List<ShopUpdateLogTable> selectShopUpdateLogs(ShopUpdateLogQuery shopUpdateLogQuery) throws Throwable {
        List<ShopUpdateLogTable> shopUpdateLogTableList = dao.select(NAMESPACE, shopUpdateLogQuery);
        if (!CommonUtil.isEmpty(shopUpdateLogTableList))
            return shopUpdateLogTableList;
        return null;
    }

    //分页查询
    public Page<ShopUpdateLogTable> selectPageLists(ShopUpdateLogQuery shopUpdateLogQuery, Integer pageNo, Integer pageSize) throws Throwable {
        Page<ShopUpdateLogTable> shopUpdateLogTablePage = dao.pageSelect(NAMESPACE,shopUpdateLogQuery,pageNo,pageSize);
        return shopUpdateLogTablePage;
    }

    //插入
    public int insert(ShopUpdateLogTable shopUpdateLogTable) throws Throwable {
        Long code = IdentityUtil.nextId(IdentityUtil.Worker.DEFAULT);
        shopUpdateLogTable.setCode(code);
        return dao.insert(NAMESPACE, shopUpdateLogTable);
    }

    //更新
    public int update(ShopUpdateLogTable shopUpdateLogTable) throws Throwable {
        return dao.update(NAMESPACE, shopUpdateLogTable);
    }

    public int delete(ShopUpdateLogTable shopUpdateLogTable) throws Throwable {
        return dao.update(NAMESPACE, shopUpdateLogTable);
    }

    //批量
    public int updateRows(ShopUpdateLogTable shopUpdateLogTable,ShopUpdateLogQuery shopUpdateLogQuery) throws Throwable {
        return dao.update(NAMESPACE,shopUpdateLogTable,shopUpdateLogQuery);
    }

    //数量
    public int count(ShopUpdateLogQuery shopUpdateLogQuery) throws Throwable {
        return dao.selectCount(NAMESPACE, shopUpdateLogQuery);
    }
}
